//
//  HangbanView.swift
//  旅航ios
//
//  Created by tulip on 2021/5/7.
//

import UIKit
import SwiftyJSON

class HangbanView: UIView {
    
    
    var isWangFan=false
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor=UIColor.black.withAlphaComponent(0.6)
       
        
      
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func remove(){
        self.removeFromSuperview()
    }
    
    
    func setUI(infoArr:Array<JSON>){
        if isWangFan {
            
            let box=UIView.init(frame: CGRect(x: 15, y: TopSpaceHeight, width: SCREEN_WIDTH-30, height: 277))
            box.backgroundColor=UIColor.white
            self.addSubview(box)
            
            let cell = HangbanViewCell.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH-30, height: 115))
            if infoArr.count > 0{
                cell.setUI(dic: infoArr[0], tagStr: "去程")
            }
           
            box.addSubview(cell)
            
            
            let cell2 = HangbanViewCell.init(frame: CGRect(x: 0, y: 116, width: SCREEN_WIDTH-30, height: 115))
            if infoArr.count > 1{
                cell.setUI(dic: infoArr[1], tagStr: "反程")
            }
           
            box.addSubview(cell2)
            
            let close=UIButton.init(frame: CGRect(x: SCREEN_WIDTH-30-75, y: 248, width: 60, height: 12))
            close.setTitle("收起详情", for: .normal)
            close.setTitleColor(UIColor.init(hexString: "357ff9"), for: .normal)
            close.addTarget(self, action: #selector(remove), for: .touchUpInside)
            close.titleLabel?.font=UIFont.systemFont(ofSize: 12)
            box.addSubview(close)
            
        }else{
            
            let box=UIView.init(frame: CGRect(x: 15, y: TopSpaceHeight, width: SCREEN_WIDTH-30, height: 170))
            box.backgroundColor=UIColor.white
            self.addSubview(box)
            
            let cell = HangbanViewCell.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH-30, height: 115))
            if infoArr.count > 0{
                cell.setUI(dic: infoArr[0], tagStr: "去程")
            }
       
            box.addSubview(cell)
        
        let close=UIButton.init(frame: CGRect(x: SCREEN_WIDTH-30-75, y: 135, width: 60, height: 12))
        close.setTitle("收起详情", for: .normal)
        close.setTitleColor(UIColor.init(hexString: "357ff9"), for: .normal)
        close.addTarget(self, action: #selector(remove), for: .touchUpInside)
        close.titleLabel?.font=UIFont.systemFont(ofSize: 12)
            box.addSubview(close)
        }
    }
    
    
}
